package week_1.homework;

import week_1.practice.ArrayStack;

import java.util.Scanner;

/**
 实现一个名为reverse的类，它使用栈把由用户输入的元素集按反序输出*/
public class reverse {
    public reverse(){}
    public void transmit(String line){
        ArrayStack flamboyant = new ArrayStack();
        String[] team=line.split(" ");
        int a = team.length;
        if (line.substring(1)==" "){
        for(int i=0;i<a;i++){
            flamboyant.push(team[i]);
        }
        for(int i = 0;i<a;i++){
            System.out.print(flamboyant.pop()+" ");
        }
    }
    else{
            for(int i=0;i<line.length();i++){
                flamboyant.push(line.charAt(i));
            }
            int m=flamboyant.size();
            for(int i = 0;i<m;i++){
                System.out.print(flamboyant.pop());
            }
        }
    }


    public static void main(String[] args) {
        reverse a = new reverse();
        Scanner sentence = new Scanner(System.in);
        System.out.println("Please input a sentence：");
        String m = sentence.nextLine();
        a.transmit(m);
    }
}

